package servlet;

import dao.UserInfo;
import dao.UserInfoService;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;

/**
 * Create By IntelliJ IDEA
 *
 * @Author: jsonor
 * @Create-Time: 2017/9/21 10:11
 * @Description: 用户登陆检测
 */
public class LoginServlet extends HttpServlet {

  private static Logger logger = Logger.getLogger(LoginServlet.class);

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    // 获取用户的请求参数
    String name = req.getParameter("name");
    String password = req.getParameter("password");
    logger.debug("username = " + name);
    logger.debug("password = " + password);
    // 和数据库中的用户存储数据进行比较
    UserInfoService service = new UserInfoService();
    if (service.hasUser(name, password)) {
      resp.getWriter().write("your can login");
    } else {
      resp.getWriter().write("gun......");
    }
  }
}
